# 生成2021HWControlRush的初赛数据集
# voyagerhui
# 20210608
# 纯随机生成

import random
from random import randint



for case in range(21):
	case_path = "TestData_"+str(case)+".case"

	# generate first line 
	N = randint(2, 1001)
	E = 0  # defined by below
	C = randint(1, 5)
	D = 0  # defined by below
	PS = randint(2000, 10001)

	# generate second line 
	line2 = []
	bas_set = []	# 基站集合
	sal_set = []	# 卫星集合
	min_sal_n = int(4*N/9)
	max_sal_n = int(7*N/9)
	satellite_num = randint(min_sal_n, max_sal_n)  # 卫星数量
	for i in range(N):
		if i < satellite_num:
			sal_set.append(i)
			line2.append(1)
		else:
			bas_set.append(i)
			line2.append(0)

	# generate the other lines
	line3 = []
	# 生成发射基站到最近的接收卫星的边
	for send in bas_set:
		recv = random.choice(sal_set)
		dist = randint(100, 800)
		E = E + 1
		D = max(D, dist)
		line3.append([send, recv, dist])
	D = D + randint(0, 1000)
	# 在卫星之间生成边
	n = len(sal_set)
	sal_edge_num = randint(n, int(n*(n-1)/2))	# 卫星间边的个数
	res = []
	while len(res) < sal_edge_num:
		send = random.choice(sal_set)
		recv = random.choice(sal_set)
		if send == recv or [send, recv] in res or [recv, send] in res:
			continue
		else:
			res.append([send, recv])
			E = E + 1

	for r in res:
		dist = randint(100, 800)
		D = max(D, dist)
		send, recv = r[0], r[1]
		line3.append([send, recv, dist])
	D = min(D, 2000)

	# output
	f = open(case_path, "a+")
	f.write(str(N)+" "+str(E)+" "+str(C)+" "+str(D)+" "+str(PS)+"\n")
	s_line2 = " ".join(str(i) for i in line2)
	f.write(s_line2+"\n")
	for t in line3:
		f.write(str(t[0])+" "+str(t[1])+" "+str(t[2])+"\n")
	f.close()
